package com.hotelvip.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hotelvip.dao.UserMapper;
import com.hotelvip.dao.VipCardMapper;
import com.hotelvip.dao.VipUserMapper;
import com.hotelvip.entity.User;
import com.hotelvip.entity.VipUser;
import com.hotelvip.service.StatisticsService;
import com.hotelvip.service.VipUserService;
import com.hotelvip.vo.Retail;
import com.hotelvip.vo.VipCardStatistics;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author:
 * @Date: 2021/3/1 10:16
 */
@Service
public class StatisticsServiceImpl implements StatisticsService {
    @Autowired
    private UserMapper userMapper;
    @Autowired
    private VipUserMapper vipUserMapper;
    @Autowired
    private VipUserService vipUserService;

    @Override
    public List<Integer> getTotalUsers() {
        return userMapper.getTotalUsers();
    }

    @Override
    public List<VipCardStatistics> getVipCardsByMonth(String date) {
        return vipUserMapper.getVipCardsByMonth(date);
    }

    @Override
    public Retail getRetail() {
        QueryWrapper<User> wrapper = new QueryWrapper<>();
        //散户查询
        wrapper.lambda().eq(User::getVStatus,0).eq(User::getDeleted,0);
        int nomalUser = userMapper.selectList(wrapper).size();
        //会员查询
        QueryWrapper<User> wrapper1 = new QueryWrapper<>();
        wrapper1.lambda().eq(User::getVStatus,1).eq(User::getDeleted,0);
        int vipUser = userMapper.selectList(wrapper1).size();
        //查詢會員卡
        QueryWrapper<VipUser> wrapper2 = new QueryWrapper<>();
        wrapper2.lambda().in(VipUser::getStatus,0,1);
        int vipCards = vipUserService.list(wrapper2).size();
        //TODO 目前房间数和资金未统计
        Retail retail = new Retail();
        retail.setNormalUser(nomalUser).setVipUser(vipUser).setVipCards(vipCards);
        return retail;
    }

}
